import request from "@/axios/axios.ts";
import {useStore} from '@/pinia'

const store = useStore()

import {HandleBalanceCRUD, HandleBalanceTableCRUD, HandleClassCRUD, HandleMemberCRUD} from "./type.ts";
import request_doc from "@/axios/request_doc.ts";

enum API1 {
    A = '/first/handle_crud',
    B = '/first/handle_class_crud',
    C = '/first/handle_balance_crud',
    D = '/first/handle_balance_table',
}

enum API2 {
    A = '/second/handle_crud',
    B = '/second/handle_class_crud',
    C = '/second/handle_balance_crud',
    D = '/second/handle_balance_table',
}
enum API3 {
    A = '/first_new/handle_crud',
    B = '/first_new/handle_class_crud',
    C = '/first_new/handle_balance_crud',
    D = '/first_new/handle_balance_table',
}
// 成员增删改查
export const reqHandleMemberCRUD = (data: HandleMemberCRUD): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.A, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.A, data)
    else
        return request.post<any, any>(API3.A, data)
}

// 分组增删改查
export const reqHandleClassCRUD = (data: HandleClassCRUD): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.B, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.B, data)
    else
        return request.post<any, any>(API3.B, data)
}

// 供应商入账记录增删改查
export const reqHandleBalanceCRUD = (data: HandleBalanceCRUD): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.C, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.C, data)
    else
        return request.post<any, any>(API3.C, data)
}


// 供应商入账记录增删改查
export const reqHandleBalanceTable = (data: HandleBalanceTableCRUD): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.D, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.D, data)
    else
        return request.post<any, any>(API3.D, data)
}
// 余额表由后端返回表格
export const MakeBalanceTable = (data: HandleBalanceTableCRUD): Promise<any> => {
    if(store.axios_path === '1')
        return request_doc.post<any, any>(API1.D, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.D, data)
    else
        return request.post<any, any>(API3.D, data)
}
